home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / dialog.win < prev    next >
Text File  |  1996-03-13  |  9KB  |  388 lines

  1. #line 2 "osdep/dialog.win"
  2.  
  3.  
  4. /*----------------------------------------------------------------------------
  5.  
  6.     Implement custom dialogs.
  7.  
  8. */
  9.  
  10.  
  11. /*
  12.  * W16 and W32 call use different names for there user data slot.
  13.  */
  14. #ifdef WIN32
  15. #define WINDOW_USER_DATA GWL_USERDATA
  16. #else
  17. #define WINDOW_USER_DATA DWL_USER
  18. #endif
  19.  
  20.  
  21.  
  22.  
  23. /*===========================================================================
  24.  *
  25.  * Dialog Data
  26.  *
  27.  * The following structures hold the state data for dialogs.
  28.  */
  29. typedef struct DLG_TYPEMAP {
  30.     int        pineid;
  31.     int        rsrcid;
  32. } DLG_TYPEMAP;
  33.  
  34. typedef struct DLG_SORTDATA {
  35.     DLG_SORTPARAM    *sortsel;    /* parameter structure. */
  36.     int            sortcount;    /* Number of different sorts. */
  37.     DLG_TYPEMAP        types[20];    /* Map pine sort types to ctrl ids. */
  38. } DLG_SORTDATA;
  39.  
  40.  
  41. typedef struct DLG_FLAGDATA {
  42.     struct flag_table    *ftbl;
  43.     int            flagcount;
  44.     HINSTANCE        hInstance;
  45.     HWND        hTextWnd;
  46. } DLG_FLAGDATA;
  47.  
  48.  
  49.  
  50. BOOL CALLBACK  __export 
  51. sort_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  52.  
  53. BOOL CALLBACK  __export 
  54. flag_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  55.  
  56.  
  57. /*
  58.  * Get a button position in the parent's coordinate space.
  59.  */
  60. static void
  61. GetBtnPos (HWND hPrnt, HWND hWnd, RECT *r)
  62. {
  63.     GetWindowRect (hWnd, r);
  64.     ScreenToClient (hPrnt, (POINT *) r);
  65.     ScreenToClient (hPrnt, (POINT *) &r->right);
  66. }
  67.  
  68.  
  69.  
  70. /*
  71.  * Select a sort type.
  72.  */
  73.  
  74. int
  75. os_sortdialog (DLG_SORTPARAM *sortsel)
  76. {
  77.     DLGPROC    dlgprc;
  78.     HINSTANCE    hInst;
  79.     HWND    hWnd;
  80.     int        i;
  81.     DLG_SORTDATA  dlgsort;
  82.  
  83.     hInst = (HINSTANCE) mswin_gethinstance ();    
  84.     hWnd = (HWND) mswin_gethwnd ();
  85.  
  86.  
  87.     /* Build a map of pine sort types to the resource types. */
  88.     i = 0;
  89.     dlgsort.types[i].pineid   = SortArrival;
  90.     dlgsort.types[i++].rsrcid = IDC_SORTARRIVAL;
  91.     dlgsort.types[i].pineid   = SortDate;
  92.     dlgsort.types[i++].rsrcid = IDC_SORTDATE;
  93.     dlgsort.types[i].pineid   = SortFrom;
  94.     dlgsort.types[i++].rsrcid = IDC_SORTFROM;
  95.     dlgsort.types[i].pineid   = SortSubject;
  96.     dlgsort.types[i++].rsrcid = IDC_SORTSUBJECT;
  97.     dlgsort.types[i].pineid   = SortSubject2;
  98.     dlgsort.types[i++].rsrcid = IDC_SORTORDERSUB;
  99.     dlgsort.types[i].pineid   = SortTo;
  100.     dlgsort.types[i++].rsrcid = IDC_SORTTO;
  101.     dlgsort.types[i].pineid   = SortCc;
  102.     dlgsort.types[i++].rsrcid = IDC_SORTCC;
  103.     dlgsort.types[i].pineid   = SortSize;
  104.     dlgsort.types[i++].rsrcid = IDC_SORTSIZE;
  105.     dlgsort.sortcount = i;
  106.     dlgsort.sortsel = sortsel;
  107.  
  108.  
  109. #ifndef WIN32
  110.     /* WIN32 obsolete */    
  111.     dlgprc = (DLGPROC) MakeProcInstance ((FARPROC) sort_dialog_proc, 
  112.                     hInst);
  113. #else
  114.     dlgprc = sort_dialog_proc;
  115. #endif
  116.  
  117.     DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_SELECTSORT), hWnd,
  118.             dlgprc, (LPARAM)&dlgsort);
  119.  
  120. #ifndef WIN32
  121.     /* WIN32 obsolete */
  122.     FreeProcInstance (dlgprc);
  123. #endif
  124. }
  125.  
  126.  
  127.  
  128.  
  129. /*
  130.  * Dialog proc to handle index sort selection.
  131.  * 
  132.  * Configures the dialog box on init and retrieves the settings on exit.
  133.  */    
  134. BOOL CALLBACK  __export 
  135. sort_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  136. {
  137.     DLG_SORTDATA *dlgsort;
  138.     BOOL ret = FALSE;
  139.     int    cursort;
  140.     int    i;
  141.  
  142.     
  143.     switch (uMsg) {
  144.     case WM_INITDIALOG:
  145.     dlgsort = (DLG_SORTDATA *)lParam;        
  146.     SetWindowLong (hDlg, WINDOW_USER_DATA, (LONG) dlgsort);
  147.     
  148.         /* Set the reversed button state. */
  149.     CheckDlgButton (hDlg, IDC_SORTREVERSE, dlgsort->sortsel->reverse);
  150.  
  151.     /* Set the current sort type radio button.*/
  152.     cursort = IDC_SORTARRIVAL;
  153.     for (i = 0; i < dlgsort->sortcount; ++i) {
  154.         if (dlgsort->types[i].pineid == dlgsort->sortsel->cursort) {
  155.             cursort = dlgsort->types[i].rsrcid;
  156.         break;
  157.         }
  158.     }
  159.     CheckRadioButton (hDlg, IDC_SORTARRIVAL, IDC_SORTDATE, cursort);
  160.  
  161.     EnableWindow (GetDlgItem (hDlg, IDC_GETHELP), 
  162.                 (dlgsort->sortsel->helptext != NULL));
  163.      return (1);
  164.  
  165.  
  166.     case WM_COMMAND:
  167.     dlgsort = (DLG_SORTDATA *) GetWindowLong (hDlg, WINDOW_USER_DATA);
  168.     switch (wParam) {
  169.     case IDC_GETHELP:
  170.         if (dlgsort->sortsel->helptext)
  171.         mswin_showhelpmsg ((WINHAND)hDlg, dlgsort->sortsel->helptext);
  172.         ret = TRUE;
  173.         break;
  174.  
  175.     case IDOK:
  176.         dlgsort->sortsel->rval = 1;
  177.  
  178.         /* Retrieve the reverse sort state. */
  179.         dlgsort->sortsel->reverse = (IsDlgButtonChecked (hDlg, IDC_SORTREVERSE) == 1);
  180.  
  181.         /* Retrieve the new sort type. */
  182.         for (i = 0; i < dlgsort->sortcount; ++i) {
  183.         if (IsDlgButtonChecked (hDlg, dlgsort->types[i].rsrcid)) {
  184.             dlgsort->sortsel->cursort = dlgsort->types[i].pineid;
  185.             break;
  186.         }
  187.         }
  188.         EndDialog (hDlg, dlgsort->sortsel->rval);
  189.         ret = TRUE;
  190.         break;
  191.  
  192.     case IDCANCEL:
  193.         dlgsort->sortsel->rval = 0;
  194.         ret = TRUE;
  195.         EndDialog (hDlg, dlgsort->sortsel->rval);
  196.         break;
  197.         }
  198.     break;
  199.     
  200.  
  201.     }
  202.     return (ret);
  203. }
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210. /*
  211.  * Select message flags.
  212.  */
  213.  
  214. int
  215. os_flagmsgdialog (struct flag_table *ftbl)
  216. {
  217.     DLGPROC    dlgprc;
  218.     HINSTANCE    hInst;
  219.     HWND    hWnd;
  220.     int        i;
  221.     DLG_FLAGDATA  dlgflag;
  222.     int        rval;
  223.  
  224.     hInst = (HINSTANCE) mswin_gethinstance ();    
  225.     hWnd = (HWND) mswin_gethwnd ();
  226.  
  227.     dlgflag.ftbl = ftbl;
  228.     dlgflag.hInstance = hInst;
  229.     dlgflag.hTextWnd  = hWnd;
  230.  
  231.  
  232. #ifndef WIN32
  233.     /* WIN32 obsolete */    
  234.     dlgprc = (DLGPROC) MakeProcInstance ((FARPROC) flag_dialog_proc, 
  235.                     hInst);
  236. #else
  237.     dlgprc = flag_dialog_proc;                   
  238. #endif
  239.     
  240.     rval = DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_SELECTFLAG), hWnd,
  241.             dlgprc, (LPARAM)&dlgflag);
  242.  
  243. #ifndef WIN32
  244.     /* WIN32 obsolete */
  245.     FreeProcInstance (dlgprc);
  246. #endif
  247.     return (rval);
  248. }
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256. /*
  257.  * Dialog proc to handle flag selection.
  258.  * 
  259.  * Configures the dialog box on init, adding buttons as needed for
  260.  * an unknown number of flags.
  261.  * Retrieves the settings on exit.
  262.  */    
  263. BOOL CALLBACK  __export 
  264. flag_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  265. {
  266.     DLG_FLAGDATA    *dlgflag;
  267.     BOOL        ret = FALSE;
  268.     int            i;
  269.     struct flag_table    *fp;
  270.     HWND        hRB[2], hBtn;
  271.     RECT        rb[2];
  272.     UINT        bheight, bwidth, bvertSpace;
  273.     UINT        btnOKHeight;
  274.     int            base, line;
  275.     int            bstate;
  276.     HFONT        btnFont;
  277.     
  278.     
  279.  
  280.     
  281.     switch (uMsg) {
  282.     case WM_INITDIALOG:
  283.      dlgflag = (DLG_FLAGDATA *)lParam;        
  284.     SetWindowLong (hDlg, WINDOW_USER_DATA, (LONG) dlgflag);
  285.  
  286.     /* Count buttons */
  287.     dlgflag->flagcount = 0;
  288.     for (fp = dlgflag->ftbl; fp && fp->name; ++fp)
  289.         ++dlgflag->flagcount;
  290.  
  291.     /* Get the positions of the current buttons. */
  292.     for (i = 0; i < 2; ++i) {
  293.         hRB[i] = GetDlgItem (hDlg, IDC_FLAGCOL1 + i);
  294.         GetBtnPos (hDlg, hRB[i], &rb[i]);
  295.     }
  296.     bheight = rb[0].bottom - rb[0].top;
  297.     bwidth  = rb[0].right  - rb[0].left;
  298.     bvertSpace = bheight + 5;
  299.     btnFont = (HFONT) SendMessage (hRB[0], WM_GETFONT, 0, 0);
  300.  
  301.     for (i = 0; i < dlgflag->flagcount; ++i) {
  302.         fp = &dlgflag->ftbl[i];
  303.         
  304.         if (i < 2) {
  305.             hBtn = hRB[i];
  306.         SetWindowText (hBtn, fp->name);
  307.         }
  308.         else {
  309.             base = i % 2;
  310.         line = i / 2;
  311.             hBtn = CreateWindow ("BUTTON", fp->name,
  312.             WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
  313.             rb[base].left, rb[base].top + bvertSpace * line,
  314.             bwidth, bheight, 
  315.             hDlg, (HMENU)NULL, dlgflag->hInstance, NULL);
  316. #ifdef    WIN32
  317.         SetWindowLong (hBtn, GWL_ID, IDC_FLAGCOL1 + i);
  318. #else
  319.             SetWindowWord (hBtn, GWW_ID, IDC_FLAGCOL1 + i);
  320. #endif
  321.             SendMessage (hBtn, WM_SETFONT, (WPARAM)btnFont, 
  322.                 MAKELPARAM (0, 0));
  323.         }
  324.         if (fp->ukn) 
  325.             SendMessage (hBtn, BM_SETSTYLE, 
  326.             (WPARAM)(BS_CHECKBOX | BS_AUTO3STATE), 0);
  327.         SendMessage (hBtn, BM_SETCHECK, 
  328.         (WPARAM) fp->set == CMD_FLAG_UNKN ? 2 :    fp->set ? 1 : 0,
  329.         0);
  330.         ShowWindow (hBtn, SW_SHOW);
  331.         EnableWindow (hBtn, TRUE);
  332.     }
  333.     
  334.     /* Position the OK and Cancel buttons. */
  335.     line = (dlgflag->flagcount + 1) / 2;
  336.     for (i = 0; i < 2; ++i) {
  337.         hRB[1] = GetDlgItem (hDlg, i == 0 ? IDOK : IDCANCEL);
  338.         GetBtnPos (hDlg, hRB[1], &rb[1]);
  339.         MoveWindow (hRB[1], rb[1].left, rb[0].top + bvertSpace * line,
  340.             rb[1].right - rb[1].left, rb[1].bottom - rb[1].top, 
  341.             FALSE);
  342.         btnOKHeight = rb[1].bottom - rb[1].top;
  343.         }
  344.     
  345.     
  346.     /* Resize whole dialog window. */
  347.     GetWindowRect (hDlg, &rb[1]);
  348.     rb[1].right -= rb[1].left;
  349.     rb[1].bottom = rb[0].top + bvertSpace * line + btnOKHeight + 10 + 
  350.                 GetSystemMetrics (SM_CYCAPTION);
  351.     MoveWindow (hDlg, rb[1].left, rb[1].top, rb[1].right,
  352.         rb[1].bottom, TRUE);
  353.      return (1);
  354.  
  355.  
  356.     case WM_COMMAND:
  357.     dlgflag = (DLG_FLAGDATA *) GetWindowLong (hDlg, WINDOW_USER_DATA);
  358.     switch (wParam) {
  359.  
  360.     case IDOK:
  361.         /* Retrieve the button states. */
  362.         for (i = 0; i < dlgflag->flagcount; ++i) {
  363.         fp = &dlgflag->ftbl[i];
  364.         bstate = SendMessage (GetDlgItem (hDlg, IDC_FLAGCOL1 + i),
  365.                     BM_GETCHECK, 0, 0);
  366.         switch (bstate) {
  367.         case 2:     fp->set = CMD_FLAG_UNKN;    break;
  368.         case 1:  fp->set = CMD_FLAG_SET;    break;
  369.         case 0:  fp->set = CMD_FLAG_CLEAR;    break;
  370.             }
  371.         }
  372.         EndDialog (hDlg, TRUE);
  373.         ret = TRUE;
  374.         break;
  375.  
  376.     case IDCANCEL:
  377.         EndDialog (hDlg, FALSE);
  378.         ret = TRUE;
  379.         break;
  380.         }
  381.     break;
  382.     
  383.  
  384.     }
  385.     return (ret);
  386. }
  387.  
  388.